//
//  SystemCDefinitions.hxx
//  sad
//
//  Created by Christopher Kemsley on 2/9/12.
//  Copyright (c) 2012 iAppolopolis. All rights reserved.
//




template <typename IOType,typename SignalType>
SystemCBinding<IOType,SignalType> :: SystemCBinding ( IOType io , SignalType signal )
:	DelayedBinding	()
,	mIO		( io )
,	mSignal	( signal )
	{
	}

template <typename IOType,typename SignalType>
void	SystemCBinding<IOType,SignalType> :: bind ()
	{
	(*mIO) ( *mSignal ) ;
	}




template <typename IOType,typename SignalType>
void	bindIOToSignal			( IOType io , SignalType signal , bool forceImmediate )
	{
	if ( forceImmediate )
		(*io) (*signal) ;
	else
		new SystemCBinding<IOType,SignalType> ( io , signal ) ;
	}

template <typename PortType,typename InterfaceType>
void	bindPortToInterface		( PortType io , InterfaceType signal , bool forceImmediate )
	{
	if ( forceImmediate )
		(*io) (*signal) ;
	else
		new SystemCBinding<PortType,InterfaceType> ( io , signal ) ;
	}


template <typename InterfaceType>
void	bindPortToInterfaceNamed	( sc_port<InterfaceType> & inPort , std::string const & intName )
	{
	Subscription<InterfaceType>	pInterface	( intName ) ;
	bindPortToInterface ( &inPort , pInterface , (pInterface!=0) ) ;
	}

template <typename SignalType>
void	bindInputToSignalNamed		( sc_in<SignalType> & inIOSignal , std::string const & intName )
	{
	Subscription < sc_signal<SignalType> >	pSignal	( intName ) ;
	bindIOToSignal ( &inIOSignal , pSignal , (pSignal!=0) ) ;
	}

template <typename SignalType>
void	bindOutputToSignalNamed		( sc_out<SignalType> & inIOSignal , std::string const & intName )
	{
	Subscription < sc_signal<SignalType> >	pSignal	( intName ) ;
	bindIOToSignal ( &inIOSignal , pSignal , (pSignal!=0) ) ;
	}



template <typename Type>
SCOutputSignal<Type> :: SCOutputSignal ()
:	mSignal		()
,	mOutput		()
,	mPublisher	()
	{
	mOutput ( mSignal ) ;
	}
template <typename Type>
SCOutputSignal<Type> :: ~SCOutputSignal ()
	{
	
	}

template <typename Type>
void	SCOutputSignal<Type> :: operator=		( std::string const & name )
	{
	mPublisher = name ;
	mPublisher = & mSignal ;
	}
template <typename Type>
void	SCOutputSignal<Type> :: operator<<	( Type const & value )
	{
	mOutput . write ( value ) ;
	}


template <typename Type>
SCInputSignal<Type> :: SCInputSignal ()
:	mInput ()
,	mSignal ()
	{
	
	}
template <typename Type>
SCInputSignal<Type> :: ~SCInputSignal ()
	{
	
	}

template <typename Type>
void			SCInputSignal<Type> :: operator=	( std::string const & name )
	{
	mSignal = name ;
	bindIOToSignal ( &mInput , mSignal ) ;
	}
template <typename Type>
Type const&		SCInputSignal<Type> :: operator*	()
	{
	return mInput -> read () ;
	}
template <typename Type>
void			SCInputSignal<Type> :: operator>>	( Type & value )
	{
	value = mInput -> read () ;
	}
template <typename Type>
sc_in<Type>*	SCInputSignal<Type> :: operator->	(  )
	{
	return & mInput ;
	}
template <typename Type>
bool			SCInputSignal<Type> :: isValid ()
	{
	return mSignal != 0 ;
	}
template <typename Type>
sc_in<Type> const&	SCInputSignal<Type> :: input ()
	{
	return mInput ;
	}
